﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CashOrCard.Models;

namespace CashOrCard.Controllers
{    
    public class HomeController : Controller
    {
        private CashOrCardContext dbContext;
        private AdvtSite advtSite;

        public HomeController(CashOrCardContext _db, AdvtSite _advtSite)
        {
            this.dbContext = _db;
            this.advtSite = _advtSite;
        }

        [HttpGet]     
        public ActionResult Index()
        {
            ViewBag.ShowBanner = true;
            var popularSites = from site in dbContext.AdvtSites.Where(x => x.IsEnable == true).OrderByDescending(x => x.SiteRate).Skip(0).Take(4)
                               select site;                                 
            return View(popularSites.ToList());
        }

        public ActionResult About(string title)
        {
            var sp = dbContext.SitePages.Where(x => x.SitePageTitle.ToLower() == title.ToLower()).FirstOrDefault();
            ViewData["spBody"] = sp.SitePageBody;
            return View(sp);
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult SitePage(string title)
        {
            var sp = dbContext.SitePages.Where(x => x.SitePageTitle.ToLower() == title.ToLower()).FirstOrDefault();
            if (sp == null)
            {
                return HttpNotFound();
            }
            ViewData["spBody"] = sp.SitePageBody;
            return View(title, sp);
        }
    }
}
